package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

//负责与dubbo的服务进行通信交互
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0") //对应my-tanhua-dubbo的service模块中RecommendUserApiImpl实现类的@Service(version = "1.0.0")注解
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long userId) {

        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(userId);
        if (null == recommendUser) {
            return null;
        }
        //recommendUser不为空,即查到了推荐用户则需对应封装一个todayBest对象
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId()); //recommendUser中的toUserId为登录用户,而userId才是给该用户推荐的用户id
        double score = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(score).longValue());//缘分值需去除小数
        //其余个人信息无需在这里做封装,外部的TodayBestService方法会做补全

        return todayBest;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long userId, Integer page, Integer pageSize) {

        return recommendUserApi.queryPageInfo(userId, page, pageSize);
    }

    //查询推荐好友的缘分值
    double queryScore(Long userId, Long toUserId) {
        return this.recommendUserApi.queryScore(userId, toUserId);
    }
}
